package web;

import pojo.Book;
import pojo.Page;
import service.BookService;
import service.impl.BookServiceImpl;
import utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ClientServlet extends BaseServlet{
    private BookService book = new BookServiceImpl();

    protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //分页查询
        int pageNo = WebUtils.paraseInt(req.getParameter("pageNo"),1);
        int pageSize = WebUtils.paraseInt(req.getParameter("pageSize"), Page.PAGE_SIZE);
        String url = "client/clientServlet?action=page";
        Page<Book> page = book.page(pageNo,pageSize,url);
        System.out.println(111);
        System.out.println(page);
        req.setAttribute("book",page);
        req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp);
    }
    protected void pageByPrice(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //分页查询
        int pageNo = WebUtils.paraseInt(req.getParameter("pageNo"),1);
        int pageSize = WebUtils.paraseInt(req.getParameter("pageSize"), Page.PAGE_SIZE);
        int max = WebUtils.paraseInt(req.getParameter("max"),Integer.MAX_VALUE);
        int min = WebUtils.paraseInt(req.getParameter("min"),0);
        String url = "client/clientServlet?action=pageByPrice&min="+min + "&max="+max;
        Page<Book> page = book.pageByPrice(pageNo,pageSize,min,max,url);
        req.setAttribute("book",page);
        req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp);
    }
}
